package com.arcpan.Controller;

import com.arcpan.Constant.BaseConstant;
import com.arcpan.Entity.Dto.SessionWebUserDto;
import com.arcpan.Entity.Query.FileInfoQuery;
import com.arcpan.Result.PageResult;
import com.arcpan.Result.Result;
import com.arcpan.Service.FileInfoService;
import com.arcpan.annotation.GlobalInterceptor;
import com.arcpan.annotation.VerifyParams;
import com.arcpan.enums.FileCategoryEnum;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/recycle")
public class RecycleController {
    @Resource
    private FileInfoService fileInfoService;
    @RequestMapping("/loadRecycleList")
    @GlobalInterceptor(checkLogin = true)
    public Result loadRecycleList(HttpSession httpSession, Integer pageNo, Integer pageSize) {
        System.out.println(pageNo);
        FileInfoQuery fileInfoQuery=new FileInfoQuery();
        SessionWebUserDto sessionWebUserDto = (SessionWebUserDto) httpSession.getAttribute(BaseConstant.SESSION_KEY);
        fileInfoQuery.setUserId(sessionWebUserDto.getUserId());
        fileInfoQuery.setOrderBy("recovery_time desc");
        fileInfoQuery.setDelFlag(1);
        PageResult pageResult = fileInfoService.getByPage(fileInfoQuery, pageNo, pageSize);

        return Result.success(pageResult);
    }
    @RequestMapping("/recoverFile")
    @GlobalInterceptor(checkLogin = true)
    public Result recoverFile(HttpSession httpSession,@VerifyParams(required = true) String fileIds){
       SessionWebUserDto sessionWebUserDto= (SessionWebUserDto) httpSession.getAttribute(BaseConstant.SESSION_KEY);
       String userId=sessionWebUserDto.getUserId();
       fileInfoService.recoverfile(userId,fileIds);
        return Result.success();
    }
    @RequestMapping("/delFile")
    @GlobalInterceptor(checkLogin = true)
    public Result delFile(HttpSession httpSession,String fileIds){
        SessionWebUserDto sessionWebUserDto= (SessionWebUserDto) httpSession.getAttribute(BaseConstant.SESSION_KEY);
        String userId=sessionWebUserDto.getUserId();
        fileInfoService.deletefile(userId,fileIds);
        return Result.success();

    }
}
